<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<head th:include="/common/inc::header"/>
<body>
<form class="layui-form" style="margin-top: 15px">
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 80px">订单号:</label>
        <div class="layui-input-inline" style="width:12%">
            <input type="text" name="billNo" id="billNo" autocomplete="off"
                   class="layui-input">
        </div>
        <label class="layui-form-label" style="width:80px">用户手机:</label>
        <div class="layui-input-inline" style="width:8%">
            <input type="text" name="account" id="account" autocomplete="off"
                   class="layui-input">
        </div>
        <label class="layui-form-label" style="width: 80px">下单时间:</label>
        <div class="layui-input-inline" style="width:7%">
            <input type="text" class="layui-input" id="addTimeSt" name="addTimeSt">
        </div>
        <div class="layui-input-inline" style="width:7%">
            <input type="text" class="layui-input" id="addTimeEt" name="addTimeEt">
        </div>
        <button class="layui-btn" id="searchBtn" lay-submit lay-filter="searchBtn">查询</button>
        <a id="down" class="layui-btn layui-btn-radius" download="佣金订单.csv" href="#">导出</a>
    </div>
</form>
<table class="layui-table" id="grid" lay-filter="grid">
</table>
<script th:replace="/common/inc::incJs"></script>
<script>
    var tableIns;
    var allStr;

    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#addTimeSt', //指定元素
            format: 'yyyy-MM-dd'
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#addTimeEt', //指定元素
            format: 'yyyy-MM-dd'
        });

    });

    $('#down').on('click', function (aLink) {
        var table = layui.table;
        var tab = allStr;
        var str = "推广用户手机,推广用户姓名,被推广用户手机,被推广用户姓名,订单佣金,下单时间,支付时间,订单编号,付款凭证号\n";
        $.each(tab, function (i, row) {
            str = str + row["account2"] + "," + row["trueName2"] + "," + row["account"] + "," + row["trueName"] + "," +
                "" + row["profitFee"] + "," + row["createTime"] + "," + row["payDate"] + "," + "SY" + row["billNo"] + "," + "SY" + row["tradeNo"] + "\n";
        });
        str = encodeURIComponent(str);
        aLink.target.href = "data:text/csv;charset:utf-8,\ufeff" + str;
    });

    $(function () {
        var t = new Date();
        t.setTime(t.getTime());
        $("#addTimeSt").val(t.format("yyyy-MM-dd"));
        tableIns = createTable({
            url: 'commissionBillList?addTimeSt=' + t.format("yyyy-MM-dd"),
            cols: [[{
                field: 'account2',
                title: '推广用户手机',
                width: 150
            }, {
                field: 'trueName2',
                title: '推广用户姓名',
                width: 150
            },
                {
                    field: 'account',
                    title: '被推广用户手机',
                    width: 150
                }, {
                    field: 'trueName',
                    title: '被推广用户姓名',
                    width: 150
                }, {
                    field: 'profitFee',
                    title: '订单佣金',
                    width: 100
                }, {field: 'createTime', title: '下单时间', width: 170}, {
                    field: 'payDate',
                    title: '支付时间',
                    width: 170
                }, {field: 'billNo', title: '订单编号', width: 220}
                , {field: 'tradeNo', title: '付款凭证号', width: 250}
            ]], height: 'full-130'
        });

        $.post('/backend/security/bill/commissionBillList', {
            addTimeSt: t.format("yyyy-MM-dd")
        }, function (res) {
            if (res.code < 0) {
                layer.msg(res.message);
            }
            else {
                allStr = res.body;
            }
        });
    })
    ;

    layui.table.on('tool(grid)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值
        var tr = obj.tr; //获得当前行 tr 的DOM对象

        if (layEvent === 'detail') { //查看
            openDialog({
                url: "/backend/security/bill/detail?id=" + data.id,
                area: ["95%", "95%"]
            });
        } else if (layEvent === 'refund') { //退款
            openDialog({
                url: "",
                area: ["95%", "95%"]
            });
        }
    });

    layui.form.on('submit(searchBtn)', function (data) {
        tableIns.reload({
            where: data.field
        });

        $.post('/backend/security/bill/commissionBillList', {
            billNo: $("#billNo").val(),
            account: $("#account").val(),
            addTimeSt: $("#addTimeSt").val(),
            addTimeEt: $("#addTimeEt").val()
        }, function (res) {
            if (res.code < 0) {
                layer.msg(res.message);
            }
            else {
                allStr = res.body;
            }
        });
        return false;
    });
</script>
<script type="text/html" id="statusTpl">
    {{#  if(d.status ===0){ }}
    <span>待支付</span>
    {{#  } else if(d.status ===1){ }}
    <span style="color: #56b02a;">待入住 </span>
    {{#  }else if(d.status ===2){ }}
    <span style="color: #56b02a;">已入住</span>
    {{#  }else if(d.status ===3){ }}
    <span style="color: #9F9F9F;">已完成</span>
    {{#  }else if(d.status ===4){ }}
    <span style="color: #FF0000;">已取消</span>
    {{#  }else if(d.status ===5){ }}
    <span style="color: blue;">已退费</span>
    {{#  } }}
</script>

<script type="text/html" id="paymentTpl">
    {{#  if(d.payment ==="wechat"){ }}
    <span>微信</span>
    {{#  } }}
</script>
<script type="text/html" id="opbar">
    <a class="layui-btn layui-btn-xs" lay-event="detail">详情</a>
    {{# if(d.status==1){ }}
    <a class="layui-btn layui-btn-xs" lay-event="refund">退款</a>
    {{# } }}
</script>
</body>
</html>
